﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using V_League.Public;

namespace V_League.DataAccess
{
    public class BTC_DataAccess
    {
        
        clsConnect cls;

        //Ham kiem tra dang nhap
        public bool checkuser(String Ma_BTC, String MKhau)
        {
            cls = new clsConnect();
            int nParameter = 2;
            String[] name = new String[nParameter];
            object[] value = new object[nParameter];

            name[0] = "@username";
            name[1] = "@password";

            value[0] = Ma_BTC;
            value[1] = MKhau;

            SqlDataReader reader = cls.ExecuteDataReader("login_BTC", name, value, nParameter);

            if (reader.HasRows)
            {
                cls.Disconnect();
                return true;
            }
            else
            {
                cls.Disconnect();
                return false;
            }
        }

        public BTC_Public GetInfo(String Ma_BTC)
        {
            cls = new clsConnect();
            BTC_Public BTC = new BTC_Public();
            int nParameter = 1;

            String[] name = new String[nParameter];
            Object[] value = new Object[nParameter];

            name[0] = "@MaBTC";
            value[0] = Ma_BTC;

            SqlDataReader reader = cls.ExecuteDataReader("getinfo_BTC", name, value, nParameter);
            while (reader.Read())
            {
                BTC.Ma_BTC = Ma_BTC;
                BTC.Ten_BTC = reader["Ten_BTC"].ToString();
                BTC.Nam = reader["Nam"].ToString();
                BTC.NKy = reader["NKy"].ToString();
                BTC.NVu = reader["NVu"].ToString();
            }
            cls.Disconnect();
            return BTC;
        }

        public DataTable GetCLBTheoMaBTC(BTC_Public BTC)
        {
            cls = new clsConnect();
            int nParameter = 1;

            String[] name = new String[nParameter];
            Object[] value = new Object[nParameter];

            name[0] = "@MaBTC";
            value[0] = BTC.Ma_BTC;

            DataTable dt = cls.LoadData("GetCLBTheoMaBTC", name, value, nParameter);

            cls.Disconnect();
            return dt;
        }
    }
}
